package com.csd.jwt.controller;

import com.csd.jwt.util.JWTUtil;
import com.csd.jwt.util.ResponseBean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @className: UserController
 * @description:
 * @author: 刘子奇
 * @date: 2019/12/9 15:31
 **/
@RestController
public class AuthController {

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public ResponseBean login(@RequestParam String username, @RequestParam String password) {
        if("admin".equals(username) && "123456".equals(password)){
            //生成token
            String token = JWTUtil.generateToken(username);

            return new ResponseBean(200, "success", token);
        }else{
            return new ResponseBean(400, "error", "username or password error");
        }
    }

}
